(function () {
    var testKey = 'test' + Date.now(),
        storage = window.sessionStorage;
    try {
        storage.setItem(testKey, '1');
        storage.removeItem(testKey);
    } catch (error) {
        var _localStorage = {};
        window.localStorage.setItem = function (k, v) {
            _localStorage[k] = v;
        };
        window.localStorage.getItem = function (k) {
            if (_localStorage.hasOwnProperty(k)) {
                return _localStorage[k];
            }
            return null;
        };

        var _sessionStorage = {};
        window.sessionStorage.setItem = function (k, v) {
            _sessionStorage[k] = v;
        };
        window.sessionStorage.getItem = function (k) {
            if (_sessionStorage.hasOwnProperty(k)) {
                return _sessionStorage[k];
            }
            return null;
        };
    }
})();